import {
  reqCategory1List,
  reqCategory2List,
  reqCategory3List
} from '@/api/product/category'
export default {
  state: {
    category1List: [],
    category2List: [],
    category3List: [],
    category1Id: undefined,
    category2Id: undefined,
    category3Id: undefined
  },
  mutations: {
    UPDATE_CATEGORY1LIST(state, category1List) {
      state.category1List = category1List
    },
    UPDATE_CATEGORY2LIST(state, category2List) {
      state.category2Id = ''
      state.category3Id = ''
      state.category3List = []
      state.category2List = []
      state.category2List = category2List
    },
    UPDATE_CATEGORY3LIST(state, category3List) {
      state.category3Id = ''
      state.category3List = []
      state.category3List = category3List
    }
  },
  actions: {
    async getCategory1List({ commit }) {
      const res = await reqCategory1List()

      if (res.code === 200) {
        commit('UPDATE_CATEGORY1LIST', res.data)
      }
    },

    async getCategory2List({ commit }, category1Id) {
      const res = await reqCategory2List(category1Id)

      if (res.code === 200) {
        commit('UPDATE_CATEGORY2LIST', res.data)
      }
    },
    async getCategory3List({ commit }, category2Id) {
      const res = await reqCategory3List(category2Id)

      if (res.code === 200) {
        commit('UPDATE_CATEGORY3LIST', res.data)
      }
    }
  },

  getters: {}
}
